package top.haijunit.work.core.annotate;

import cn.hutool.core.util.DesensitizedUtil;
import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.function.Function;

/**
 * 脱敏类型枚举类
 *
 * @author zhanghaijun
 * @since 2024-08-09
 */
@Getter
@AllArgsConstructor
public enum DesensitizeType {
    /**
     * 默认脱敏
     */
    DEFAULT(s -> StrUtil.repeat('*', Math.max(StrUtil.length(s), 4))),

    /**
     * 手机号脱敏
     */
    PHONE(DesensitizedUtil::mobilePhone),
    /**
     * 电子邮件脱敏
     */
    EMAIL(DesensitizedUtil::email),
    /**
     * 身份证号脱敏
     */
    ID_CARD(s -> DesensitizedUtil.idCardNum(s, 3, 4)),
    /**
     * 银行卡号脱敏
     */
    BANK_CARD(DesensitizedUtil::bankCard),
    /**
     * 地址脱敏
     */
    ADDRESS(s -> DesensitizedUtil.address(s, 8)),
    /**
     * 中文姓名脱敏
     */
    CHINESE_NAME(DesensitizedUtil::chineseName),
    /**
     * 密码脱敏
     */
    PASSWORD(DesensitizedUtil::password),
    ;

    // 可自行添加其他脱敏策略
    private final Function<String, String> desensitize;

}
